//
//  RHDeviceTopoMEView.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/2/29.
//

#import "RHDeviceTopoMEView.h"
@interface RHDeviceTopoMEView()
@property (nonatomic, strong) UIImageView *topoImg;

@property (nonatomic ,strong) QMUILabel *batGroupVolLab;

@property (nonatomic ,strong) QMUILabel *batGroupTempLab;

@property (nonatomic ,strong) QMUILabel *batSocLab;

@property (nonatomic ,strong) QMUILabel *batSohLab;

@property (nonatomic ,strong) QMUILabel *batBreakerLab;//交流断路器

@property (nonatomic ,strong) QMUILabel *batStockTempLab;

@property (nonatomic ,strong) QMUILabel *batStockHumLab;

@property (nonatomic ,strong) QMUILabel *pscStateLab;

@property (nonatomic ,strong) QMUILabel *totalPowerLab;

@property (nonatomic ,strong) QMUILabel *condenserLab;//交流断路器
@end
@implementation RHDeviceTopoMEView
-(instancetype)init
{
    if(self = [super init]){
        [self setupUI];

    }
    return self;
}

-(void)setTopo233Model:(RH233TopoModel *)topo233Model
{
    _topo233Model = topo233Model;
    
    //soc
    NSString *socStr = [NSString stringWithFormat:@"%@%%",[NSDecimalNumber decimalStringWithDouble:topo233Model.soc nullStr:@"--"]];
    self.batSocLab.text = [NSString stringWithFormat:@"%@",socStr];
    
    //soh
    NSString *sohStr = [NSString stringWithFormat:@"%@%%",[NSDecimalNumber decimalStringWithDouble:topo233Model.soh nullStr:@"--"]];
    self.batSohLab.text = [NSString stringWithFormat:@"%@",sohStr];
    
    //电池组电压,温度(显示第2个)
    NSString *vol2 = [NSDecimalNumber decimalStringWithDouble:topo233Model.pack2Voltage nullStr:@"--"];
    self.batGroupVolLab.text = [NSString stringWithFormat:@"%@V",vol2];
    NSString *temp2 = [NSDecimalNumber decimalStringWithDouble:topo233Model.pack2Temperature nullStr:@"--"];
    self.batGroupTempLab.text = [NSString stringWithFormat:@"%@℃",temp2];
    //断路器
    self.batBreakerLab.text = topo233Model.exDevIO04?@"闭合".rh_localized:@"断开".rh_localized;
    
    //电池仓温度
    NSString *stockTemp = [NSDecimalNumber decimalStringWithDouble:topo233Model.batCaseTemp nullStr:@"--"];
    self.batStockTempLab.text = [NSString stringWithFormat:@"%@℃",stockTemp];
    //电池仓湿度
    NSString *stockHum = [NSDecimalNumber decimalStringWithDouble:topo233Model.batCaseHumidity nullStr:@"--"];
    self.batStockHumLab.text = [NSString stringWithFormat:@"%@%%RH",stockHum];
    
    //pcs工作状态
    NSString *pcsState = @"--";
    switch (topo233Model.pcsRunningStatus) {
        case 0:
            pcsState = @"停止".rh_localized;
            break;
        case 1:
            pcsState = @"待机".rh_localized;
            break;
        case 2:
            pcsState = @"故障".rh_localized;
            break;
        case 3:
            pcsState = @"充电".rh_localized;
            break;
        case 4:
            pcsState = @"放电".rh_localized;
            break;
        case 5:
            pcsState = @"充电降额".rh_localized;
            break;
        case 6:
            pcsState = @"放电降额".rh_localized;
            break;
        default:
            break;
    }
    self.pscStateLab.text = pcsState;
    
    //总有功功率
    NSString *totalPower = [NSDecimalNumber decimalStringWithDouble:topo233Model.pcsActivePwr nullStr:@"--"];
    self.totalPowerLab.text = [NSString stringWithFormat:@"%@kW",totalPower];
    
    //液冷工作状态
    NSString *lcus = @"--";
    //0:停止1:内循环2:制冷3:加热4:全自动(根据水温)，
    switch (topo233Model.lcustatus) {
        case 0:
            lcus = @"停止".rh_localized;
            break;
        case 1:
            lcus = @"内循环".rh_localized;
            break;
        case 2:
            lcus = @"制冷".rh_localized;
            break;
        case 3:
            lcus = @"加热".rh_localized;
            break;
        case 4:
            lcus = @"全自动".rh_localized;
            break;
        default:
            break;
    }
    self.condenserLab.text = lcus;
}


-(void)setupUI
{
    kWeakSelf;
    UIImage *image = [UIImage imageNamed:@"me_dc_233"];
    _topoImg = [[UIImageView alloc]initWithImage:image];
    [self addSubview:_topoImg];
    [_topoImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(15);
        make.bottom.mas_offset(-15);
        make.left.mas_offset(kScaleW(70));
        make.right.mas_offset(kScaleW(-70));
        make.width.equalTo(_topoImg.mas_height).multipliedBy(image.size.width/image.size.height);
    }];
    
    _batGroupVolLab =  [QMUILabel labelWithText:@"--V".rh_localized font:kSYSTEMFONT(12) textColor:kCOLOR_HEX_A(@"132B88", 0.8)];
    [self addSubview:_batGroupVolLab];
    [_batGroupVolLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.mas_offset(15);
    }];
    QMUILabel *batGroupVolTitleLab = [QMUILabel labelWithText:@"电池组电压".rh_localized font:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"171A1D", 0.6)];
    [self addSubview:batGroupVolTitleLab];
    [batGroupVolTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.batGroupVolLab);
        make.top.equalTo(weakSelf.batGroupVolLab.mas_bottom).offset(5);
    }];
    
    
    _batGroupTempLab =  [QMUILabel labelWithText:@"--℃".rh_localized font:kSYSTEMFONT(12) textColor:kCOLOR_HEX_A(@"132B88", 0.8)];
    [self addSubview:_batGroupTempLab];
    [_batGroupTempLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(batGroupVolTitleLab.mas_bottom).offset(15);
    }];
    QMUILabel *batGroupTempTitleLab = [QMUILabel labelWithText:@"电池组温度".rh_localized font:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"171A1D", 0.6)];
    [self addSubview:batGroupTempTitleLab];
    [batGroupTempTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.batGroupTempLab);
        make.top.equalTo(weakSelf.batGroupTempLab.mas_bottom).offset(5);
    }];
    
    
    _batSocLab =  [QMUILabel labelWithText:@"--%".rh_localized font:kSYSTEMFONT(12) textColor:kCOLOR_HEX_A(@"132B88", 0.8)];
    [self addSubview:_batSocLab];
    [_batSocLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(batGroupTempTitleLab.mas_bottom).offset(15);
    }];
    QMUILabel *socTitleLab = [QMUILabel labelWithText:@"电池SOC".rh_localized font:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"171A1D", 0.6)];
    [self addSubview:socTitleLab];
    [socTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.batSocLab);
        make.top.equalTo(weakSelf.batSocLab.mas_bottom).offset(5);
    }];
    
    
    _batSohLab =  [QMUILabel labelWithText:@"--%".rh_localized font:kSYSTEMFONT(12) textColor:kCOLOR_HEX_A(@"132B88", 0.8)];
    [self addSubview:_batSohLab];
    [_batSohLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(socTitleLab.mas_bottom).offset(15);
    }];
    QMUILabel *sohTitleLab = [QMUILabel labelWithText:@"电池SOH".rh_localized font:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"171A1D", 0.6)];
    [self addSubview:sohTitleLab];
    [sohTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.batSohLab);
        make.top.equalTo(weakSelf.batSohLab.mas_bottom).offset(5);
    }];
    
    _batBreakerLab =  [QMUILabel labelWithText:@"--".rh_localized font:kSYSTEMFONT(12) textColor:kCOLOR_HEX_A(@"132B88", 0.8)];
    [self addSubview:_batBreakerLab];
    
    QMUILabel *batBreakerTitleLab = [QMUILabel labelWithText:@"交流断路器状态".rh_localized font:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"171A1D", 0.6)];
    [self addSubview:batBreakerTitleLab];
    
    [_batBreakerLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.bottom.equalTo(batBreakerTitleLab.mas_top).offset(-5);
    }];
    [batBreakerTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.batBreakerLab);
        make.bottom.equalTo(weakSelf.topoImg.mas_bottom).offset(kScaleW(-15));
    }];
    
    //-------------------------------------------------------------------
    
    
    _batStockTempLab =  [QMUILabel labelWithText:@"--℃".rh_localized font:kSYSTEMFONT(12) textColor:kCOLOR_HEX_A(@"132B88", 0.8)];
    [self addSubview:_batStockTempLab];
    [_batStockTempLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.topoImg.mas_right).offset(kScaleW(-3));
        make.top.mas_offset(15);
    }];
    QMUILabel *batStockTempTitleLab = [QMUILabel labelWithText:@"电池仓温度".rh_localized font:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"171A1D", 0.6)];
    batStockTempTitleLab.textAlignment = NSTextAlignmentLeft;
    batStockTempTitleLab.numberOfLines = 3;
    batStockTempTitleLab.adjustsFontSizeToFitWidth = YES;
    batStockTempTitleLab.minimumScaleFactor = 0.8;
    [self addSubview:batStockTempTitleLab];
    [batStockTempTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.batStockTempLab);
        make.right.mas_offset(-3);
        make.top.equalTo(weakSelf.batStockTempLab.mas_bottom).offset(5);
    }];
   
    
    _batStockHumLab =  [QMUILabel labelWithText:@"--%RH".rh_localized font:kSYSTEMFONT(12) textColor:kCOLOR_HEX_A(@"132B88", 0.8)];
    [self addSubview:_batStockHumLab];
    [_batStockHumLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.batStockTempLab).offset(0);
        make.top.equalTo(batStockTempTitleLab.mas_bottom).offset(5);
    }];
    QMUILabel *batStockHumTitleLab = [QMUILabel labelWithText:@"电池仓湿度".rh_localized font:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"171A1D", 0.6)];
    batStockHumTitleLab.textAlignment = NSTextAlignmentLeft;
    batStockHumTitleLab.numberOfLines = 3;
    batStockHumTitleLab.adjustsFontSizeToFitWidth = YES;
    batStockHumTitleLab.minimumScaleFactor = 0.8;
    [self addSubview:batStockHumTitleLab];
    [batStockHumTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.batStockHumLab);
        make.right.mas_offset(-3);
        make.top.equalTo(weakSelf.batStockHumLab.mas_bottom).offset(5);
    }];
    
    _pscStateLab =  [QMUILabel labelWithText:@"--".rh_localized font:kSYSTEMFONT(12) textColor:kCOLOR_HEX_A(@"132B88", 0.8)];
    [self addSubview:_pscStateLab];
    [_pscStateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.batStockTempLab).offset(0);
        make.top.equalTo(weakSelf.topoImg.mas_centerY).offset(kScaleW(5));
    }];
    QMUILabel *pcsStateTitleLab = [QMUILabel labelWithText:@"PCS工作状态".rh_localized font:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"171A1D", 0.6)];
    pcsStateTitleLab.textAlignment = NSTextAlignmentLeft;
    pcsStateTitleLab.numberOfLines = kUI_WINDOW_W==375?1:2;
    pcsStateTitleLab.adjustsFontSizeToFitWidth = YES;
    pcsStateTitleLab.minimumScaleFactor = 0.5;
    [self addSubview:pcsStateTitleLab];
    [pcsStateTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.pscStateLab);
        make.right.mas_offset(-3);
        make.top.equalTo(weakSelf.pscStateLab.mas_bottom).offset(5);
    }];
    
    _totalPowerLab =  [QMUILabel labelWithText:@"--kW".rh_localized font:kSYSTEMFONT(12) textColor:kCOLOR_HEX_A(@"132B88", 0.8)];
    [self addSubview:_totalPowerLab];
    [_totalPowerLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.batStockTempLab).offset(0);
        make.top.equalTo(pcsStateTitleLab.mas_bottom).offset(5);
    }];
    QMUILabel *totalPowerTitleLab = [QMUILabel labelWithText:@"总有功功率".rh_localized font:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"171A1D", 0.6)];
    totalPowerTitleLab.textAlignment = NSTextAlignmentLeft;
    totalPowerTitleLab.numberOfLines = kUI_WINDOW_W==375?1:2;
    totalPowerTitleLab.adjustsFontSizeToFitWidth = YES;
    totalPowerTitleLab.minimumScaleFactor = 0.5;
    [self addSubview:totalPowerTitleLab];
    [totalPowerTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.totalPowerLab);
        make.right.mas_offset(-3);
        make.top.equalTo(weakSelf.totalPowerLab.mas_bottom).offset(5);
    }];
    
    
    _condenserLab =  [QMUILabel labelWithText:@"--".rh_localized font:kSYSTEMFONT(12) textColor:kCOLOR_HEX_A(@"132B88", 0.8)];
    _condenserLab.adjustsFontSizeToFitWidth = YES;
    _condenserLab.minimumScaleFactor = 0.8;
    _condenserLab.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_condenserLab];
    
    QMUILabel *condenserTitleLab = [QMUILabel labelWithText:@"液冷机组工作状态".rh_localized font:kSYSTEMFONT(10) textColor:kCOLOR_HEX_A(@"171A1D", 0.6)];
    condenserTitleLab.textAlignment = NSTextAlignmentLeft;
    condenserTitleLab.numberOfLines = 2;
    condenserTitleLab.adjustsFontSizeToFitWidth = YES;
    condenserTitleLab.minimumScaleFactor = 0.8;
    [self addSubview:condenserTitleLab];
    
    [_condenserLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.batStockTempLab).offset(0);
        make.right.mas_offset(0);
        make.bottom.equalTo(condenserTitleLab.mas_top).offset(-5);
    }];
    
    [condenserTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.condenserLab);
        make.right.mas_offset(0);
        make.bottom.mas_offset(kScaleW(-10));
    }];
    
    condenserTitleLab.hidden = YES;
    _condenserLab.hidden = YES;

}
@end
